﻿using DocumentFormat.OpenXml.Lite.Core.Interfaces;
using DocumentFormat.OpenXml.Lite.Core.Office;
using DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Base;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Table
{
    [XmlRoot("tblGrid", Namespace = Constants.WordMain)]
    public class TableGrid : XmlSerializable, IOfficeElement
    {
        [XmlIgnore]
        public Guid DocumentId { get; set; }

        [Optional]
        [XmlElement("gridCol", Namespace = Constants.WordMain)]
        public XmlList<GridColumn> GridColumns { get; set; }

        /// <summary>
        /// Revision Information for Table Grid Column Definitions
        /// </summary>
        [Optional]
        [XmlElement("tblGridChange", Namespace = Constants.WordMain)]
        public GridChange TableGridChange {
            get { return gridChange; }
            set { gridChange = value; gridChange.DocumentId = this.DocumentId; }
        }

        [XmlIgnore]
        private GridChange gridChange;

        public TableGrid()
        {
            GridColumns = new XmlList<GridColumn>();
        }

        public GridColumn AddGridColumn()
        {
            GridColumn gc = new GridColumn();
            GridColumns.Add(gc);
            return gc;
        }

        public GridColumn AddGridColumn(uint width)
        {
            GridColumn gc = new GridColumn() { Width = width };
            GridColumns.Add(gc);
            return gc;
        }
    }
}
